package com.fuhao.springbootrabbit.Service;

import com.fuhao.springbootrabbit.constant.RabbitConstant;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author zhang
 * @title: TopicService
 */
@Service
public class TopicService{
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void topicSend(){
        Map<Object,String> map = new HashMap<>();
        map.put("username","Lisa");

        //构建回调返回的数据
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(RabbitConstant.TOPIC_EXCHANGE_NAME,"test.topic.add",map,correlationData);
    }

//    //回调方法
//    @Override
//    public void confirm(CorrelationData correlationData, boolean isSendSuccess, String s) {
//        System.out.println("confirm回调方法>>>>>>>>>>>>>回调消息ID为: " + correlationData.getId());
//        if (isSendSuccess) {
//            System.out.println("confirm回调方法>>>>>>>>>>>>>消息发送成功");
//        } else {
//            System.out.println("confirm回调方法>>>>>>>>>>>>>消息发送失败" + s);
//        }
//    }
}
